package student.aistar.day14;

/**
 * 泛型类
 */
public class GenericClassDemo<T> {
    //定义属性
    private T type;

    public GenericClassDemo(){

    }

    //将类型参数化传递
    public GenericClassDemo(T type) {
        this.type = type;
    }

    //泛型方法
    public T getType() {
        return type;
    }

    public void setType(T type) {
        this.type = type;
    }

    public static void main(String[] args) {
        GenericClassDemo c = new GenericClassDemo();
        c.setType("区分");
        System.out.println(c.getType());
        c.setType(123);
        System.out.println(c.getType());


        GenericClassDemo<String> c1 = new GenericClassDemo();
        c1.setType("覃烽");
        System.out.println(c1.getType());
//        c1.setType(123); //error


        GenericClassDemo<Integer> c2 = new GenericClassDemo<>();
        c2.setType(213);
        System.out.println(c2.getType());

    }
}
